#include "StdAfx.h"
#include "PropFactory.h"
#include "PropHolder.h"
#include "ScriptProp.h"
#include "EditorGuidDef.h"
CPropFactory::CPropFactory(void)
{

}

CPropFactory::~CPropFactory(void)
{

}

void CPropFactory::Initialize()
{

}
void CPropFactory::AddPropScript(const CString& szID, const CString& szScript)
{
	m_PropScrips[szID] = szScript;
}
CPropHolder* CPropFactory::CreateProp(const CString& szId)
{
	CPropHolder* pProp = CreateObject(szId);
	if(pProp == NULL)
	{
		CString szScritp;
		if(FindPropScritp(szId, szScritp))
			pProp = new CScriptProp(szScritp);
	}

	return pProp;
}

bool CPropFactory::FindPropScritp(const CString& szID, CString& szScript)
{
	PropMaps::const_iterator it = m_PropScrips.find(szID);
	if(it != m_PropScrips.end())
	{
		szScript = it->second;
		return true;
	}
	return false;
}
//////////////////////////////////////////////////////////////////////////

CRegPropHelper::CRegPropHelper(const CString& guid, CPropCreator* pPropCreator)
:m_Guid(guid)
{
	RegisterProp(pPropCreator);
}

CRegPropHelper::~CRegPropHelper()
{
	//GetPropFactory().UnRegisterObject(m_Guid);
}

void CRegPropHelper::RegisterProp(CPropCreator* pPropCreator)
{
	bool bResult = GetPropFactory().RegisterObject(m_Guid, pPropCreator);
	ASSERT(bResult);
}